package it.mauriziulu.android.ehttpexecutors.request;

import org.apache.http.params.HttpParams;

public class RequestBuilder {
	private String mUri;
	private String mMethod;
	private HttpParams mParams;
	private EHttpRequest mRequest;

	public RequestBuilder() {
	}

	public static RequestBuilder newInstance() {
		return new RequestBuilder();
	}

	public RequestBuilder setUrl(String url) {
		mUri = url;
		return this;
	}

	public RequestBuilder setMethod(String method) {
		mMethod = method;
		return this;
	}

	public RequestBuilder setParameter(HttpParams parameters) {
		mParams = parameters;
		return this;
	}

	public EHttpRequest build() throws Exception {
		if (mUri == null || mMethod == null) {
			throw new Exception("Method or URL not set");
		}// TODO: validare
		mRequest = new EHttpRequest(mMethod, mUri);
		if (mParams != null) {
			mRequest.setParams(mParams);
		}
		return mRequest;
	}
}
